﻿using System;
using System.Activities;
using System.Activities.Validation;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WFExtended.Framework.Constraints
{
    /// <summary>
    /// Activity Constraint for check that an activity is not inside of parent activity types
    /// </summary>
    /// <typeparam name="A">Type of the activity to check</typeparam>
    public class NotBeInsideConstraint<A> : AActivityTypesConstraint<A>
        where A : Activity
    {

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="isWarning">Define if the constraint is a warning</param>
        /// <param name="propertyName">Contraint property name</param>
        /// <param name="parentActivityTypes">List of parent activity types to check</param>
        public NotBeInsideConstraint(bool isWarning, string propertyName, params Type[] parentActivityTypes)
            : base(isWarning, true, propertyName, parentActivityTypes)
        {

        }

        /// <summary>
        /// Get the list of parent activities
        /// </summary>
        /// <param name="validationContext">Context for the current node in the workflow tree</param>
        /// <returns></returns>
        public override Activity<IEnumerable<Activity>> GetActivitiesToValidate(DelegateInArgument<ValidationContext> validationContext)
        {
            return new GetParentChain
            {
                ValidationContext = validationContext
            };
        }

        /// <summary>
        /// Get the error Message
        /// </summary>
        public override string ErrorMessage
        {
            get
            {
                return String.Format("{0} is inside activity of Type {1}",
                                typeof(A).Name, String.Join(",", _activityTypes.Select((T) => T.Name)));
            }
        }

    }
}
